package com.mofang.powerdekorhelper.utils.http;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by luofei on 2017/1/5 0005.
 */

public class InitRetrofit {

    private static InitRetrofit initRetrofit;

    public static InitRetrofit getInstance() {
        if (initRetrofit == null) {
            initRetrofit = new InitRetrofit();
        }
        return initRetrofit;
    }

    Retrofit retrofit;

    RetrofitSerives requestSerives;

    /**
     * 初始化Retrofit
     */
    public RetrofitSerives getRetrofit(String baseIp) {

        retrofit = new Retrofit.Builder()
                .baseUrl(baseIp)
                //增加返回值为String的支持
                .addConverterFactory(ScalarsConverterFactory.create())
                //增加返回值为Gson的支持(以实体类返回)
                .addConverterFactory(GsonConverterFactory.create())
                //增加返回值为Oservable<T>的支持
                //.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

        //这里采用的是Java的动态代理模式
        requestSerives = retrofit.create(RetrofitSerives.class);

        return requestSerives;
    }
}
